﻿using System;
using System.IO ;
using System.Text;

namespace CodeGenerator
{
    class Program
    {

        static void Main(string[] args)
        {

            // Command line parsing
            StreamWriter s_Writer;
            ArgumentsSimplify CommandLine=new ArgumentsSimplify(args);

            // them if they exist (return null if they don't)
            Console.WriteLine("Parameters :");
            Console.WriteLine("");
            if(CommandLine["class_path"] != null)
                Console.WriteLine("* class_path = " + CommandLine["class_path"]);

            if (CommandLine["oracle_db"] != null)
                Console.WriteLine("* oracle_db = " + CommandLine["oracle_db"]);


            // Wait for key.
            Console.Out.WriteLine("\r\nArguments parsed. Press a key to continue.");
            Console.Read();

            // Load Assembly.
            kernel.AssemblyParser o_Parser = new kernel.AssemblyParser(CommandLine["class_path"]);

            if(CommandLine["class_path"] != null)
            {
                // Parsing Assembly 
                o_Parser.Parsing(ScriptType.Debug );
                Console.Out.WriteLine(o_Parser.GetBuffer() );

                // Create SQL script to create database objects.
                o_Parser.Parsing(ScriptType.CodeScripts)  ;
                Console.WriteLine("[ALTER.SQL    ] - Creato script per creazione oggetti database!");
                s_Writer = new StreamWriter("ALTER.SQL");
                s_Writer.WriteLine(o_Parser.GetBuffer());
                s_Writer.Close();

                // Create SQL script to create database objects.
                o_Parser.Parsing(ScriptType.DataObjectsScripts );
                Console.WriteLine("[Code.cs      ] - Creato codice!");
                s_Writer = new StreamWriter("Code.cs");
                s_Writer.WriteLine(o_Parser.GetBuffer());
                s_Writer.Close();
            };


            if (CommandLine["oracle_db"] != null)
            {
                // Create a class from database structure.
                o_Parser.DatabaseToClass();
                Console.WriteLine("[Data.cs      ] - Creata classe base dati!");
                s_Writer = new StreamWriter("Data.cs");
                s_Writer.WriteLine(o_Parser.GetBuffer());
                s_Writer.Close();

            }; 
            
            Console.Read();
            Console.Out.WriteLine("\r\nPress a key to exit.");
            Console.Read();
            
        }



    }
}
